<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/static/include/topLess2.jsp"%>
<script>document.title="评估指标";</script>

<script src="${baseURL}/static/js/jquery.easyui.min.js"></script>
<script src="${baseURL}/static/js/ajaxfileupload.js"></script>
<link href="${baseURL}/static/js/themes/default/easyui.css" rel="stylesheet" type="text/css" />

<c:set var="userAreaId" value="${sessionScope.user.userAreaId}"></c:set>
<c:set var="pid" value="${requestScope.areasMap[sessionScope.user.userAreaId].parentId}"></c:set>

<style type="text/css">
<!--
table {
	margin:0;
	width:0;
	font-family:"微软雅黑";
	font-size:12px;
	color: #FFF;
	border-collapse: collapse;
}
//-->
</style>

<table id="search_t" style="width:98%">
		<tbody>
			<tr>
				<th><img src="${ctx}/static/images/pages/cen/rig/ico_01.png" align="middle">&nbsp;评估指标
				</th>
			</tr>
			<tr class="tab_grey">
				<td>
					<input type="hidden" id="areaId" name="areaId" value="${userAreaId}">
					选择条件：
					<input id="country" name="country" type="checkbox" value="0">&nbsp;全国
				<c:choose>
					<c:when test="${pid eq '0'}">
						<span class="tab_text">省(自治区、直辖市):</span>
					</c:when>
					<c:when test="${requestScope.areasMap[pid].parentId eq '0'}">
						<span class="tab_text">地(区、市、州、盟):</span>
					</c:when>
					<c:otherwise>
						<span class="tab_text">县(区、市、旗):</span>
					</c:otherwise>
				</c:choose>
				
				<input type="text" class="tab_textbut" value="${sessionScope.user.userAreaName}" readonly>

				<c:if test="${pid eq '0'}">
					<span class="tab_text">地(区、市、州、盟):</span>
					<select class="tab_textbut" id="areaId2" onchange="queryAreasByParent(this)">
						<option value="">请选择..</option>
						<option value="${requestScope.areasMap['320600000000000'].id}">${requestScope.areasMap['320600000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320700000000000'].id}">${requestScope.areasMap['320700000000000'].areaName}</option>
						<option value="${requestScope.areasMap['320900000000000'].id}">${requestScope.areasMap['320900000000000'].areaName}</option>
					</select>
				</c:if>

				<c:if test="${pid eq '0' || requestScope.areasMap[pid].parentId eq '0'}">
					<span class="tab_text">县(区、市、旗):</span>
					<select class="tab_textbut_100" id="areaId3">
						<option value="">请选择..</option>
						
						<c:if test="${requestScope.areasMap[pid].parentId eq '0'}">
							<c:forEach items="${requestScope.areasMap}" var="area">
								<c:if test="${requestScope.areasMap[pid].id eq area.value.parentId}">
								<option value="${area.value.id}">${area.value.areaName}</option>								
								</c:if>
							</c:forEach>
						</c:if>
						
					</select>
				</c:if>
				<br/>
				<span class="tab_text">评估频率：</span>
				<select id="timeType" name="timeType" class="tab_textbut">
					<option value="">请选择..</option>
					<option value="1">年报</option>
					<option value="3">半年报</option>
					<option value="2">季报</option>
				</select>
				<select id="quarter" name="endYear" class="tab_textbut" style="display: none">
					<option value="1">第一季度</option>
					<option value="2">第二季度</option>
					<option value="3">第三季度</option>
					<option value="4">第四季度</option>
				</select>
				<span class="tab_text">年份:</span>
				<select id="startYear" name="startYear" class="tab_textbut">
					<option value="">请选择..</option>
				</select>
				
				<a class="tab_but02" href="#" onclick="indicatorEvaluation();return false;">生成评估指标</a>
				<a class="tab_but02" href="#" onclick="queryData();return false;">查询评估结果</a>
				
				<br>
				<div style="position: relative;">
				<form name="uploadForm" id="uploadForm" target="upload" action="${baseURL}/audit/importIndicator/${sessionScope.user.id}" method="post" enctype="multipart/form-data">
				数据类型:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				
				<input type="radio" value="1" id="templateType" name="templateType">国民经济代码&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" value="2" id="templateType" name="templateType">直接消耗系数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" value="3" id="templateType" name="templateType">基本流量表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				
				<a class="tab_but" href="#" onclick="downTemplate();return false;">下载模板</a>
				
				<input type="file" class="tab_but" style="position:absolute; cursor:pointer; filter:alpha(opacity:0);opacity: 0; top:0; left:520px; height:24px; width:80px" name="fileField" class="file" id="fileField" size="28" onchange="uploadFile(this);return false;" />
				<a class="tab_but" href="#" onclick="return false;">数据导入</a>
				</form>
				</div>
				</td>
			</tr>
		</tbody>
</table>

<br>
<div id="dataList" style="overflow:auto;width:98%">
<table id="dg" class="easyui-datagrid" style="width:1000px;height:450px"   
        data-options="fitColumns:true,singleSelect:true">
    <thead>   
        <tr>   
            <th data-options="field:'year',width:80,align:'center'">评估年份</th>   
            <th data-options="field:'indicatorName',width:150">指标名称</th>   
            <th data-options="field:'indicatorValue',width:120,align:'right'">指标值</th>
            <th data-options="field:'indicatorUnit',width:80,align:'right'">单位</th>
            <th data-options="field:'operate',width:120,align:'center'">操作</th>
        </tr>   
    </thead>   
</table>
</div>

<div id="downDiv" style="display:none">
</div>

<script language="javaScript">

	var pageNum = 1;
	var pageSize = 10;

	$().ready(function(){
		
		$('#win').window('close');

		var startYear = ${requestScope.versionYearList.startYear};
		var endYear = ${requestScope.versionYearList.endYear};
		
		for (var i=startYear; i<=endYear; i++){
			$("#startYear").append("<option>" + i + "</option>");
		}
		
		$("#timeType").bind("change", function(){
			if (this.value=="2"){	//季报
				$("#quarter").show();
			}else{
				$("#quarter").hide();
			}
		});
	});
	
	function validate(){

		if ($("#timeType").val()==""){
			layer.alert("请选择评估频率");
			return;
		}
		
		if ($("#startYear").val()==""){
			layer.alert("请选择年份");
			return;
		}		
		
		$("#areaId").val("${userAreaId}");
		
		if ($("#areaId2").val()!="" && $("#areaId2").val() != undefined){
			$("#areaId").val($("#areaId2").val());
		}
		
		if ($("#areaId3").val()!="" && $("#areaId3").val() != undefined){
			$("#areaId").val($("#areaId3").val());
		}
		
		if ($("input:checkbox:checked").val()){
			$("#areaId").val("0");	
		}
		return true;
	}
		
	//表单提交查询
	function queryData(){

		if (!validate()){
			return;
		}
		
		var timeYear;
		var quarter;
		
		if ($("#timeType").val()=="1"){
			timeYear = 2;
		}else if ($("#timeType").val()=="3"){
			timeYear = 1;
		}else if ($("#timeType").val()=="2"){
			quarter = $("#quarter").val();			
		}
		
		
		var quarter;
		
		var url = "${baseURL}/audit/queryIndicatorEvaluation";
		var params = {
				pageNum:pageNum, 
				timeYear:timeYear, 
				timeType:$("#timeType").val(), 
				quarter:quarter, 
				areaId:$("#areaId").val(), 
				year:$("#startYear").val(),
				category1:"${requestScope.typeName}",
				category2:"${requestScope.subType}"
				};
		
		$('#dg').datagrid({
		    url:url,
		    pagination:true,
		    pageSize:pageSize,
		    rownumbers:true,
		    queryParams:params,
		    columns:[[
		        {field:'year',width:80,align:'center',title:'评估年份'},
		        {field:'indicatorName',width:150, title:'指标名称'},   
		        {field:'indicatorValue',width:120,align:'right',title:'指标值'}, 
		        {field:'indicatorUnit',width:80,align:'right',title:'单位'}, 
		        {field:'operate',width:120,align:'center',title:'操作'}
		    ]],
		    loadFilter: function(data){
		    	data.rows = data.operationResult;
		    	data.total = data.totalCount;
		    	
		    	$.each(data.operationResult, function(i, row){

		    	});
		    	
		    	
		    	return data;
			}
		}); 
	}

	function winClose(){
		layer.closeAll();	
	}
	
	//生成评估结果
	function indicatorEvaluation(){
		if (!validate()){
			return;
		}
		
		var yearTime;
		var quarter;
		
		var params = "timeType=" + $("#timeType").val() + "&areaId=" + $("#areaId").val() + "&year=" + $("#startYear").val();
		
		params = params + "&category1=${requestScope.typeName}&category2=${requestScope.subType}";

		if ($("#timeType").val()=="1"){
			yearTime = 2;
		}else if ($("#timeType").val()=="3"){
			yearTime = 1;
		}else if ($("#timeType").val()=="2"){
			params = params + "&quarter=" + $("#quarter").val();
		}
		
		params = params +  "&yearTime=" + yearTime;
		
		var url = "${baseURL}/audit/indicatorEvaluation";
		

		$.ajax({
			url: url,
			type: 'post',
			dataType: 'json',
			data : params,
			beforeSend: function(){
				loadi = layer.load('数据生成中…');
			},
			complete: function(){
				layer.close(loadi);
			},
			success: function(msg){
				if (msg=="1"){
					queryData();  //显示查询结果
				}
			}
		});
		

	}
	
	function queryAreasByParent(obj){
		$.getJSON("${baseURL}/area/queryAreasByParent/" + obj.value, function(json){
			$("#areaId3").empty();
			$("#areaId3").append("<option value=''>请选择..</option>");
			$.each(json, function(i, area){
				$("#areaId3").append("<option value='" + area.id + "'>" + area.areaName + "</option>");
			});
		});
	}
	
	
	function downTemplate(){
		var url = "${baseURL}/indicator-stat.do?method=gdpCodeTemple";
		
		var year = $("#startYear").val();
		
		var yearTime = $("#templateType:checked").val();
		
		if (year==""){
			layer.alert("请选择起始时间");
			return;
		}

		if (!yearTime){
			layer.alert("请选择模板类型");
			return;
		}

		
		url = url + "&provinceId=" + $("#startYear").val() + "&yearTime=" + yearTime;
		
		var iframe = document.createElement("iframe");
		iframe.src = url;
		document.getElementById("downDiv").appendChild(iframe);
	}
	
	//指标数据导入
	function uploadFile(obj){
		
		var uid = "";
		
		var templateType = $("#templateType:checked").val();
		
		if (templateType=="1"){
			uid = "codeUp";
		}else if (templateType=="2"){
			uid = "consumpUp";
		}else if (templateType=="3"){
			uid = "baseUp";
		}
		
		if (!templateType){
			layer.alert("请选择模板类型");
			return;
		}

		
		var url = "${baseURL}/audit/importIndicator/" + uid;

		$.ajaxFileUpload({
			url:url,
			fileElementId:'fileField',
			secureuri:false,
			dataType:'json',
			type:'post',
			success: function(msg){
				$.layer.msg(msg, 1, 1);
			},
			error: function(msg){
				
			}
		});

	}
	
</script>




<%@ include file="/static/include/bottom.jsp"%>